#include "CountDevice.h"
#include <stdio.h>
#include <string.h>

CountDevice::CountDevice(int max, int start)
{
	_counter = start;
	_increment = 10;
	_min = 0;//-max;
	_max = max;
}

CountDevice::~CountDevice()
{
}

int CountDevice::open()
{
	_isOpen = 1;
	printf("Count device open\n");
	return 0;
}

void CountDevice::close()
{
	_isOpen = 0;
	printf("Count device closed\n");
}

int CountDevice::read()
{
	if (!_isOpen)
	{
		printf("Read failed: count device not open\n"); 
	}
	if (_counter >= _max)
		_increment = -10;
	if (_counter <= _min)
		_increment = 10;
	
	_counter += _increment;
	return _counter;
}
